package com.bitdf.txing.group.feign.impl.order;

import com.bitdf.txing.cart.feign.vo.CartItem;
import com.bitdf.txing.cart.service.CartService;
import com.bitdf.txing.order.feign.OrderCartFeignService;
import com.bitdf.txing.order.vo.OrderItemVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Lizhiwei
 * @date 2023/9/5 23:31:02
 * 注释：
 */
@Service
@ConditionalOnProperty(value = "tx.deploy.mode", havingValue = "standalone")
public class OrderCartFeignServiceImpl implements OrderCartFeignService {
    @Autowired
    CartService cartService;
    @Override
    public List<OrderItemVo> getCurrentUserCartItems() {
        List<CartItem> userCartItems = cartService.getUserCartItems();
        List<OrderItemVo> collect = userCartItems.stream().map(item -> {
            OrderItemVo orderItemVo = new OrderItemVo();
            BeanUtils.copyProperties(item, orderItemVo);
            return orderItemVo;
        }).collect(Collectors.toList());
        return collect;
    }
}
